 package org.jfbmonitor.view.transaction;

import java.awt.FontMetrics;

import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;

import org.jfbmonitor.language.Language;

public class TransactionColumnModel extends DefaultTableColumnModel {
	private static final long serialVersionUID = 1L;
	
	
	public TransactionColumnModel(FontMetrics fm){
		int number = fm.stringWidth("0");
		int character = fm.stringWidth("M");
		
		addColumn(createColumn(0, 14 * number, fm, Language.getInstance()
				.getProperties("TABLE.TRANSACTIONID")));		
		addColumn(createColumn(1, 14 * number, fm, Language.getInstance()
				.getProperties("TABLE.ATTACHMENTID")));		
		addColumn(createColumn(2, 6 * character, fm, Language.getInstance()
				.getProperties("TABLE.STATE")));
		addColumn(createColumn(3, 14 * character, fm, Language.getInstance()
				.getProperties("TABLE.TIMESTAMP")));
		addColumn(createColumn(4, 15 * number, fm, Language.getInstance()
				.getProperties("TABLE.TOPTRANSACTION")));		
		addColumn(createColumn(5, 17 * number, fm, Language.getInstance()
				.getProperties("TABLE.OLDESTTRANSACTION")));		
		addColumn(createColumn(6, 15 * number, fm, Language.getInstance()
				.getProperties("TABLE.OLDESTACTIVE")));		
		addColumn(createColumn(7, 25 * character, fm, Language.getInstance()
				.getProperties("TABLE.ISOLATIONMODE")));		
		addColumn(createColumn(8, 20 * character, fm, Language.getInstance()
				.getProperties("TABLE.LOCKTIMEOUT")));		
		addColumn(createColumn(9, 12 * number, fm, Language.getInstance()
				.getProperties("TABLE.READONLY")));		
		addColumn(createColumn(10, 12 * number, fm, Language.getInstance()
				.getProperties("TABLE.AUTOCOMMIT")));		
		addColumn(createColumn(11, 12 * number, fm, Language.getInstance()
				.getProperties("TABLE.AUTOUNDO")));
		addColumn(createColumn(12, 12 * number, fm, Language.getInstance()				
				.getProperties("TABLE.STATID")));
		
	}

	private TableColumn createColumn(int columnIndex, int width,
			FontMetrics fm, String title) {
		TableColumn col = new TableColumn(columnIndex);
		col.setCellRenderer(new TransactionCellRenderer());
		col.setHeaderRenderer(null);
		col.setHeaderValue(title);
		col.setResizable(true);
		col.setMinWidth(0);
		col.setMaxWidth(width);
		return col;
	}

}
